<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录页面</title>
    <link href="css/logincss/default.css" rel="stylesheet" type="text/css" />
    <!--必要样式-->
    <link href="css/logincss/styles.css" rel="stylesheet" type="text/css" />
    <link href="css/logincss/demo.css" rel="stylesheet" type="text/css" />
    <link href="css/logincss/loaders.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="easyui/js/jquery.min.js"></script>
    <style type="text/css">
    </style>
    <script>

    </script>
</head>
<body>
<div class='login'>
    <div class='login_title'>
        <span>CRM-客户关系管理系统</span>
    </div>
    <form id="login-form" action="" method="post">
        <div class='login_fields'>
            <div class='login_fields__user'>
                <div class='icon'>
                    <img alt="" src='images/img/user_icon_copy.png'>
                </div>
                <input name="login" placeholder='username' maxlength="16" type='text' autocomplete="off" />
                <div class='validation'>
                    <img alt="" src='images/img/tick.png'>
                </div>
            </div>
            <div class='login_fields__password'>
                <div class='icon'>
                    <img alt="" src='images/img/lock_icon_copy.png'>
                </div>
                <input name="pwd" placeholder='password' maxlength="16" type='text' autocomplete="off">
                <div class='validation'>
                    <img alt="" src='images/img/tick.png'>
                </div>
            </div>
            <div class='login_fields__password'>
                <div class='icon'>
                    <img alt="" src='images/img/key.png'>
                </div>
                <input name="code" placeholder='code' maxlength="4" type='text' name="ValidateNum" autocomplete="off">
                <div class='validation' style="opacity: 1; right: -5px;top: -3px;">
                    <canvas class="J_codeimg" id="myCanvas" onclick="Code();">对不起，您的浏览器不支持canvas，请下载最新版浏览器!</canvas>
                </div>
            </div>
            <div class='login_fields__submit'>
                <input id="sub-btn" type='button' value='登录'>
            </div>
        </div>
    </form>
    <div class='success'>
    </div>
    <div class='disclaimer'>
        <p>欢迎登陆后台管理系统</p>
    </div>
</div>
<div class='authent'>
    <div class="loader" style="height: 44px;width: 44px;margin-left: 28px;">
        <div class="loader-inner ball-clip-rotate-multiple">
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
    <p>认证中...</p>
</div>
<div class="OverWindows"></div>
<link href="js/layui/css/layui.css" rel="stylesheet" type="text/css" />
<script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
<script type="text/javascript" src="js/loginjs/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/loginjs/stopExecutionOnTimeout.js?t=1"></script>
<script type="text/javascript" src="js/layui/layui.js" ></script>
<script type="text/javascript" src="js/loginjs/Particleground.js" ></script>
<script type="text/javascript" src="js/loginjs/Treatment.js"></script>
<script type="text/javascript" src="js/loginjs/jquery.mockjax.js"></script>
<script type="text/javascript">
    var canGetCookie = 0;//是否支持存储Cookie 0 不支持 1 支持
    var CodeVal = 0;
    Code();
    function Code() {
        if(canGetCookie == 1){
            createCode("AdminCode");
            var AdminCode = getCookieValue("AdminCode");
            showCheck(AdminCode);
        }else{
            showCheck(createCode(""));
        }
    }
    function showCheck(a) {
        CodeVal = a;
        var c = document.getElementById("myCanvas");
        var ctx = c.getContext("2d");
        ctx.clearRect(0, 0, 1000, 1000);
        ctx.font = "80px 'Hiragino Sans GB'";
        ctx.fillStyle = "#E8DFE8";
        ctx.fillText(a, 0, 100);
    }
    $(document).keypress(function (e) {
        // 回车键事件
        if (e.which == 13) {
            $('input[type="button"]').click();
        }
    });
    //粒子背景特效
    $('body').particleground({
        dotColor: '#E8DFE8',
        lineColor: '#E8DFE8'
    });
    $('input[name="pwd"]').focus(function () {
        $(this).attr('type', 'password');
    });
    $('input[type="text"]').focus(function () {
        $(this).prev().animate({ 'opacity': '1' }, 200);
    });
    $('input[type="text"],input[type="password"]').blur(function () {
        $(this).prev().animate({ 'opacity': '.5' }, 200);
    });
    $('input[name="login"],input[name="pwd"]').keyup(function () {
        var Len = $(this).val().length;
        if (!$(this).val() == '' && Len >= 5) {
            $(this).next().animate({
                'opacity': '1',
                'right': '30'
            }, 200);
        } else {
            $(this).next().animate({
                'opacity': '0',
                'right': '20'
            }, 200);
        }
    });
    var open = 0;
    layui.use('layer', function () {

        //非空验证
        $('input[type="button"]').click(function () {
            var login = $('input[name="login"]').val();
            var pwd = $('input[name="pwd"]').val();
            var code = $('input[name="code"]').val();
            if (login == '') {
                ErroAlert('请输入您的账号');
            } else if (pwd == '') {
                ErroAlert('请输入密码');
            } else if (code == '' || code.length != 4) {
                ErroAlert('输入验证码');
            }else if(code.toUpperCase()!=CodeVal.toUpperCase()){
                ErroAlert('验证码输入不正确');
            }else {
                //认证中..
                fullscreen();
                $('.login').addClass('test'); //倾斜特效
                setTimeout(function () {
                    $('.login').addClass('testtwo'); //平移特效
                }, 300);
                setTimeout(function () {
                    $('.authent').show().animate({ right: -320 }, {
                        easing: 'easeOutQuint',
                        duration: 600,
                        queue: false
                    });
                    $('.authent').animate({ opacity: 1 }, {
                        duration: 200,
                        queue: false
                    }).addClass('visible');
                }, 500);

                //登陆
                var JsonData = { login: login, pwd: pwd};
                //ajax调用路径
                var url = "toLogins";

                AjaxPost(url, JsonData,
                    function () {
                        //ajax加载中
                    },
                    function (result) {
                        //ajax返回
                        //认证完成
                        setTimeout(function () {
                            $('.authent').show().animate({ right: 90 }, {
                                easing: 'easeOutQuint',
                                duration: 600,
                                queue: false
                            });
                            $('.authent').animate({ opacity: 0 }, {
                                duration: 200,
                                queue: false
                            }).addClass('visible');
                            $('.login').removeClass('testtwo'); //平移特效
                        }, 2000);
                        setTimeout(function () {
                            $('.authent').hide();
                            $('.login').removeClass('test');
                            if (result.success) {
                                //登录成功
                                $('.login div').fadeOut(100);
                                $('.success').fadeIn(1000);
                                // $('.success').html(data.Text);
                                location.href="crmIndex";
                                //跳转操作

                            } else {
                                // AjaxErro(data);
                                //登录错误
                                 ErroAlert('用户名或密码错误');
                                 
                                //清空表单内容
                                resertForm();
                            }
                        }, 2400);
                    })
            }
        })
    });
    var fullscreen = function () {
        elem = document.body;
        if (elem.webkitRequestFullScreen) {
            elem.webkitRequestFullScreen();
        } else if (elem.mozRequestFullScreen) {
            elem.mozRequestFullScreen();
        } else if (elem.requestFullScreen) {
            elem.requestFullscreen();
        } else {
            //浏览器不支持全屏API或已被禁用
        }
    }
    // if(ajaxmockjax == 1){
    //     $.mockjax({
    //         url: 'Ajax/Login',
    //         status: 200,
    //         responseTime: 50,
    //         responseText: {"Status":"ok","Text":"登陆成功<br /><br />欢迎回来"}
    //     });
    //     $.mockjax({
    //         url: 'Ajax/LoginFalse',
    //         status: 200,
    //         responseTime: 50,
    //         responseText: {"Status":"Erro","Erro":"账号名或密码或验证码有误"}
    //     });
    // }
    //清空表单内容
    function  resertForm(){
                 $(':input','#login-form')
                 .not(':button, :submit, :reset, :hidden')
                 .val('')
                 .removeAttr('checked')
                 .removeAttr('selected');
             }
</script>
</body>
</html>
